package com.niodata.dp.log;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.apache.log4j.Logger;


public class LogUtil {

  public static void logStackTrace(Logger logger, Exception ex) {
    try {
      String stackTrace = getStackTrace(ex);
      logger.error(stackTrace);
    } catch (Exception e) {
      //no ex
    }
  }

  public static String getStackTrace(Throwable t) throws IOException {
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    t.printStackTrace(printWriter);
    printWriter.close();
    try {
      stringWriter.close();
    } catch (IOException e) {
      //no ex
    }
    return stringWriter.toString();
  }
}
